<?php
/**
 * SDK 广告类
 *
 */
class SDK_Advertise
{
    const _CONST_TB_DEFAULT_ = 'sdk_ad_package';

    protected static $_infos = array();
    protected static $_infos_dirty = TRUE;

    public static function info ($advertise_id)
    {
        self::load_all_infos ();
        return Arr::get(self::$_infos, $advertise_id);
    }

    public static function price ($advertise_id)
    {
        $info  = self::info($advertise_id);
        $price = Arr::get($info, 'price', 60);
        return $price;
    }

    protected static function load_all_infos ()
    {
        if (self::$_infos_dirty)
        {
            $query = DB::select()
                ->from(self::_CONST_TB_DEFAULT_)
                ->execute();

            $info = array();
            foreach ($query as $rs)
            {
                $id = $rs['id'];
                $info[$id] = $rs;
            }

            self::$_infos = $info;
            self::$_infos_dirty = FALSE;
        }
    }
}
